# coding:utf-8

import serial
import threading
from multiprocessing import Process as process
from time import sleep
import sys,time

def get_print(comport):
    ser = serial.Serial(comport,baudrate=115200,bytesize=8,parity='N',stopbits=1,timeout=1)
    with open('m3.txt','w',encoding="gb18030") as f:
        mark = 0
        while 1:
            sleep(0.9)
            mark += 1
            if ser.inWaiting():
                x=ser.read(150)
                lll = x.decode('gb18030','replace')
                f.write(lll)
                f.flush()

if __name__ == '__main__':
    start_time = time.time()

    #comport = sys.argv[1]
    comport = '/dev/ttyUSB0'

    p1 = process(target=get_print, args=(comport,))
    p1.daemon=True
    p1.start()
    sleep(15)
    end_time = time.time()
    print("\n处理完毕。共耗时 %s 秒\n" % round(float(end_time-start_time),2) )

